import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
const routes: Array<RouteRecordRaw> = []

interface RequireContext {
  keys(): string[];
  <T>(id: string): T;
}


//扫描routerModules
const req = require.context('./modules', true, /\.ts$/)
const requireAll = (context: RequireContext) => context.keys().map(context)

interface Module { default: RouteRecordRaw[] }
requireAll(req).forEach((route) => {
  (route as Module).default.forEach(route => routes.push(route))
})


const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
